﻿using Manon.Admin.Web.Application;
using Manon.Admin.Web.Application.Dtos;
using Manon.Admin.Web.Application.Dtos.Member;
using Manon.Core;
using Manon.Repository.Collections;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Manon.Admin.Web.Controllers
{
    public class MemberController : Controller
    {
        private readonly IMemberService _memberService;
        public MemberController(IMemberService memberService)
        {
            _memberService = memberService;
        }

        #region 会员管理
        public IActionResult Index()
        {
            return View();
        }
        public IActionResult Edit()
        {
            return View();
        }

        [Authorize]
        [HttpGet]
        public async Task<List<GetMemberLevelOutput>> GetMemberLeveldList()
        { 
            var result = await _memberService.GetMemberLevelList();

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<PagedList<GetMemberOutput>> GetMemberPagedList([FromBody] GetMemberPagedListInput Input)
        { 
            var result = await _memberService.GetMemberPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveMember([FromBody] SaveMemberInput Input)
        { 
            var result = await _memberService.SaveMember(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<GetMemberOutput> GetMember(int Id)
        { 
            var result = await _memberService.GetMember(Id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetMemberEnabled(int Id, bool Enabled)
        { 
            var result = await _memberService.SetMemberEnabled(Id, Enabled);
            return result;
        }

        #endregion




        #region 会员等级
        public IActionResult Level()
        {
            return View();
        }

        public IActionResult LevelEdit()
        {
            return View();
        }


        [Authorize]
        [HttpPost]
        public async Task<PagedList<GetMemberLevelOutput>> GetMemberLevelPagedList([FromBody] GetMemberLevelPagedListInput Input)
        { 
            var result = await _memberService.GetMemberLevelPagedList(Input);

            return result;
        }

        [Authorize]
        [HttpPost]
        public async Task<Result> SaveMemberLevel([FromBody] SaveMemberLevelInput Input)
        { 
            var result = await _memberService.SaveMemberLevel(Input);
            return result;
        }
        [Authorize]
        [HttpGet]
        public async Task<GetMemberLevelOutput> GetMemberLevel(int Id)
        { 
            var result = await _memberService.GetMemberLevel(Id);
            return result;
        }
        [Authorize]
        [HttpPost]
        public async Task<Result> SetMemberLevelEnabled(int Id, bool Enabled)
        { 
            var result = await _memberService.SetMemberLevelEnabled(Id, Enabled);
            return result;
        }
        #endregion
    }
}
